package com.lemon.es.config;

import com.lemon.es.properties.EsConfigProperties;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 李猛
 * @datetime 2024/2/22 15:49
 * @description 类对象
 */
@Configuration
@EnableConfigurationProperties(EsConfigProperties.class) // 依赖配置文件
public class EsConfig {
    @Bean
    public RestHighLevelClient restHighLevelClient(EsConfigProperties properties) {
        HttpHost httpHost = new HttpHost(properties.getHost(), properties.getPort(), properties.getType());
        RestClientBuilder clientBuilder = RestClient.builder(httpHost);
        return new RestHighLevelClient(clientBuilder);
    }
}
